##
# server.py - Created by Timothy Morey on 6/10/2012
#
# This file provides a ctypes wrapper for libnvn items defined in server.h.
#

import ctypes

from libnvn import nvn

# ServerMode enum values:
ServerModeChatty = 0
ServerModeStream = 1

class Server(ctypes.Structure):
    pass

ServerRequestCallback = ctypes.CFUNCTYPE(ctypes.c_int, 
                                         ctypes.POINTER(Server), ctypes.c_char_p, 
                                         ctypes.POINTER(ctypes.c_char), ctypes.c_int, 
                                         ctypes.POINTER(ctypes.c_char), ctypes.POINTER(ctypes.c_int))

Server._fields_ = [
                   ('Port',                  ctypes.c_int),
                   ('ServerRequestCallback', ServerRequestCallback),
                   ('ReceiveBuffer',         ctypes.POINTER(ctypes.c_char)),
                   ('ReceiveBufferLength',   ctypes.c_int),
                   ('ManageReceiveBuffer',   ctypes.c_int),
                   ('SendBuffer',            ctypes.POINTER(ctypes.c_char)),
                   ('SendBufferLength',      ctypes.c_int),
                   ('ManageSendBuffer',      ctypes.c_int),
                   ('Async',                 ctypes.c_int),
                   ('ServerMode',            ctypes.c_int),
                  ]

StartAsyncServer = nvn.StartAsyncServer
StartAsyncServer.argtypes = [ctypes.c_int, ServerRequestCallback, ctypes.c_int]
StartAsyncServer.restype = ctypes.POINTER(Server)

StartServer = nvn.StartServer
StartAsyncServer.argtypes = [ctypes.c_int, ServerRequestCallback, ctypes.c_int]

SetReceiveBuffer = nvn.SetReceiveBuffer
SetReceiveBuffer.argtypes = [ctypes.POINTER(Server), 
                             ctypes.POINTER(ctypes.c_char), ctypes.c_int, ctypes.c_int]

SetSendBuffer = nvn.SetSendBuffer
SetSendBuffer.argtypes = [ctypes.POINTER(Server), 
                          ctypes.POINTER(ctypes.c_char), ctypes.c_int, ctypes.c_int]

StopServer = nvn.StopServer
StopServer.argtypes = [ctypes.POINTER(Server)]